const app = getApp();
import req from '../../utils/Request.js';
import appReq from '../../utils/AppRequest.js';

Page({
  data: {
    list: null,
  },

  onLoad: function () {
    this.getDetail()
  },

  previewImg: function (e) {
    let index = e.currentTarget.dataset.index;
    let imgArr = this.data.list[index].housesTypePicture;
    wx.previewImage({
      current: imgArr,     //当前图片地址
      urls: [imgArr],               //所有要预览的图片的地址集合 数组形式
      success: function (res) { },
      fail: function (res) { },
      complete: function (res) { },
    })
  },

  getDetail: function () {
    req.get('/index/getCustomerCollectList.do', { openId: app.globalData.openId }).then(res => {
      if (res.code == 1) {
       
        this.setData({
          list: res.data.map(i => {
            i.img = i.housePicture.split(",")[0]
            return i
          }),
        })
        console.log(this.data.list)
        wx.hideLoading();
      } else {
        app.showErrorMessage(res, '加载失败');
        wx.hideLoading();
        return;
      }
    }).catch(res => {
      wx.hideLoading();
      wx.showToast({
        title: '网络异常',
        icon: 'none'
      });
      console.log(res);
    });
  },

  goDetail: function (e) {
    let _index = e.currentTarget.dataset.index;
    wx.navigateTo({
      url: '../detail/index?keyId=' + this.data.list[_index].keyId
    })
  }


})